package com.film.service.impl.movie;

import com.alibaba.fastjson.JSONObject;
import com.film.service.movie.FetchMoviesService;
import com.film.utils.MySqlConnection;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;

@Service
public class FetchMovieCategoriesServiceImpl implements FetchMoviesService {
    @Override
    public JSONObject fetchMovies() throws SQLException {
        JSONObject resp = new JSONObject();
        LinkedList<String> categories = new LinkedList<>();
        Statement stmt = MySqlConnection.connect.createStatement();
        String sql = "select * from Class";
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            String item = resultSet.getString("classname");
            categories.add(item);
        }

        resp.put("categories", categories);
        resp.put("error_message", "success");
        return resp;
    }
}
